
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>懒加载 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="scroll-behavior.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../installation.html">
            
                <a href="../installation.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    基础
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../essentials/getting-started.html">
            
                <a href="../essentials/getting-started.html">
            
                    
                    开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../essentials/dynamic-matching.html">
            
                <a href="../essentials/dynamic-matching.html">
            
                    
                    动态路由匹配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../essentials/nested-routes.html">
            
                <a href="../essentials/nested-routes.html">
            
                    
                    嵌套路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../essentials/navigation.html">
            
                <a href="../essentials/navigation.html">
            
                    
                    编程式导航
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../essentials/named-routes.html">
            
                <a href="../essentials/named-routes.html">
            
                    
                    命名路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../essentials/named-views.html">
            
                <a href="../essentials/named-views.html">
            
                    
                    命名视图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../essentials/redirect-and-alias.html">
            
                <a href="../essentials/redirect-and-alias.html">
            
                    
                    重定向 和 别名
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../essentials/history-mode.html">
            
                <a href="../essentials/history-mode.html">
            
                    
                    HTML5 History 模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    进阶
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="navigation-guards.html">
            
                <a href="navigation-guards.html">
            
                    
                    导航钩子
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="meta.html">
            
                <a href="meta.html">
            
                    
                    路由元信息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="transitions.html">
            
                <a href="transitions.html">
            
                    
                    过渡动效
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="data-fetching.html">
            
                <a href="data-fetching.html">
            
                    
                    数据获取
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="scroll-behavior.html">
            
                <a href="scroll-behavior.html">
            
                    
                    滚动行为
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.6" data-path="lazy-loading.html">
            
                <a href="lazy-loading.html">
            
                    
                    懒加载
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    API 文档
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../api/router-link.html">
            
                <a href="../api/router-link.html">
            
                    
                    router-link
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../api/router-view.html">
            
                <a href="../api/router-view.html">
            
                    
                    router-view
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../api/route-object.html">
            
                <a href="../api/route-object.html">
            
                    
                    路由信息对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../api/options.html">
            
                <a href="../api/options.html">
            
                    
                    Router 构造配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../api/router-instance.html">
            
                <a href="../api/router-instance.html">
            
                    
                    Router 实例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../api/component-injections.html">
            
                <a href="../api/component-injections.html">
            
                    
                    对组件注入
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >懒加载</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x8DEF;&#x7531;&#x61D2;&#x52A0;&#x8F7D;">&#x8DEF;&#x7531;&#x61D2;&#x52A0;&#x8F7D;</h1>
<p>&#x5F53;&#x6253;&#x5305;&#x6784;&#x5EFA;&#x5E94;&#x7528;&#x65F6;&#xFF0C;Javascript &#x5305;&#x4F1A;&#x53D8;&#x5F97;&#x975E;&#x5E38;&#x5927;&#xFF0C;&#x5F71;&#x54CD;&#x9875;&#x9762;&#x52A0;&#x8F7D;&#x3002;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x80FD;&#x628A;&#x4E0D;&#x540C;&#x8DEF;&#x7531;&#x5BF9;&#x5E94;&#x7684;&#x7EC4;&#x4EF6;&#x5206;&#x5272;&#x6210;&#x4E0D;&#x540C;&#x7684;&#x4EE3;&#x7801;&#x5757;&#xFF0C;&#x7136;&#x540E;&#x5F53;&#x8DEF;&#x7531;&#x88AB;&#x8BBF;&#x95EE;&#x7684;&#x65F6;&#x5019;&#x624D;&#x52A0;&#x8F7D;&#x5BF9;&#x5E94;&#x7EC4;&#x4EF6;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x66F4;&#x52A0;&#x9AD8;&#x6548;&#x4E86;&#x3002;</p>
<p>&#x7ED3;&#x5408; Vue &#x7684; <a href="http://vuejs.org/guide/components.html#Async-Components" target="_blank">&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;</a> &#x548C; Webpack &#x7684; <a href="https://webpack.js.org/guides/code-splitting-require/" target="_blank">code splitting feature</a>, &#x8F7B;&#x677E;&#x5B9E;&#x73B0;&#x8DEF;&#x7531;&#x7EC4;&#x4EF6;&#x7684;&#x61D2;&#x52A0;&#x8F7D;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x8981;&#x505A;&#x7684;&#x5C31;&#x662F;&#x628A;&#x8DEF;&#x7531;&#x5BF9;&#x5E94;&#x7684;&#x7EC4;&#x4EF6;&#x5B9A;&#x4E49;&#x6210;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> Foo = resolve =&gt; {
  <span class="hljs-comment">// require.ensure &#x662F; Webpack &#x7684;&#x7279;&#x6B8A;&#x8BED;&#x6CD5;&#xFF0C;&#x7528;&#x6765;&#x8BBE;&#x7F6E; code-split point</span>
  <span class="hljs-comment">// &#xFF08;&#x4EE3;&#x7801;&#x5206;&#x5757;&#xFF09;</span>
  <span class="hljs-built_in">require</span>.ensure([<span class="hljs-string">&apos;./Foo.vue&apos;</span>], () =&gt; {
    resolve(<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./Foo.vue&apos;</span>))
  })
}
</code></pre>
<p>&#x8FD9;&#x91CC;&#x8FD8;&#x6709;&#x53E6;&#x4E00;&#x79CD;&#x4EE3;&#x7801;&#x5206;&#x5757;&#x7684;&#x8BED;&#x6CD5;&#xFF0C;&#x4F7F;&#x7528; AMD &#x98CE;&#x683C;&#x7684; require&#xFF0C;&#x4E8E;&#x662F;&#x5C31;&#x66F4;&#x7B80;&#x5355;&#x4E86;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> Foo = resolve =&gt; <span class="hljs-built_in">require</span>([<span class="hljs-string">&apos;./Foo.vue&apos;</span>], resolve)
</code></pre>
<p>&#x4E0D;&#x9700;&#x8981;&#x6539;&#x53D8;&#x4EFB;&#x4F55;&#x8DEF;&#x7531;&#x914D;&#x7F6E;&#xFF0C;&#x8DDF;&#x4E4B;&#x524D;&#x4E00;&#x6837;&#x4F7F;&#x7528; <code>Foo</code>&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> router = <span class="hljs-keyword">new</span> VueRouter({
  routes: [
    { path: <span class="hljs-string">&apos;/foo&apos;</span>, component: Foo }
  ]
})
</code></pre>
<h3 id="&#x628A;&#x7EC4;&#x4EF6;&#x6309;&#x7EC4;&#x5206;&#x5757;">&#x628A;&#x7EC4;&#x4EF6;&#x6309;&#x7EC4;&#x5206;&#x5757;</h3>
<p>&#x6709;&#x65F6;&#x5019;&#x6211;&#x4EEC;&#x60F3;&#x628A;&#x67D0;&#x4E2A;&#x8DEF;&#x7531;&#x4E0B;&#x7684;&#x6240;&#x6709;&#x7EC4;&#x4EF6;&#x90FD;&#x6253;&#x5305;&#x5728;&#x540C;&#x4E2A;&#x5F02;&#x6B65; chunk &#x4E2D;&#x3002;&#x53EA;&#x9700;&#x8981; <a href="https://webpack.js.org/guides/code-splitting-require/#chunkname" target="_blank">&#x7ED9; chunk &#x547D;&#x540D;</a>&#xFF0C;&#x63D0;&#x4F9B; <code>require.ensure</code> &#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x4F5C;&#x4E3A; chunk &#x7684;&#x540D;&#x79F0;:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> Foo = r =&gt; <span class="hljs-built_in">require</span>.ensure([], () =&gt; r(<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./Foo.vue&apos;</span>)), <span class="hljs-string">&apos;group-foo&apos;</span>)
<span class="hljs-keyword">const</span> Bar = r =&gt; <span class="hljs-built_in">require</span>.ensure([], () =&gt; r(<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./Bar.vue&apos;</span>)), <span class="hljs-string">&apos;group-foo&apos;</span>)
<span class="hljs-keyword">const</span> Baz = r =&gt; <span class="hljs-built_in">require</span>.ensure([], () =&gt; r(<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./Baz.vue&apos;</span>)), <span class="hljs-string">&apos;group-foo&apos;</span>)
</code></pre>
<p>Webpack &#x5C06;&#x76F8;&#x540C; chunk &#x4E0B;&#x7684;&#x6240;&#x6709;&#x5F02;&#x6B65;&#x6A21;&#x5757;&#x6253;&#x5305;&#x5230;&#x4E00;&#x4E2A;&#x5F02;&#x6B65;&#x5757;&#x91CC;&#x9762; &#x2014;&#x2014; &#x8FD9;&#x4E5F;&#x610F;&#x5473;&#x7740;&#x6211;&#x4EEC;&#x65E0;&#x987B;&#x660E;&#x786E;&#x5217;&#x51FA; <code>require.ensure</code> &#x7684;&#x4F9D;&#x8D56;&#xFF08;&#x4F20;&#x7A7A;&#x6570;&#x7EC4;&#x5C31;&#x884C;&#xFF09;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="scroll-behavior.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: 滚动行为">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"懒加载","level":"1.4.6","depth":2,"next":{"title":"API 文档","level":"1.5","depth":1,"ref":"","articles":[{"title":"router-link","level":"1.5.1","depth":2,"path":"api/router-link.md","ref":"api/router-link.md","articles":[]},{"title":"router-view","level":"1.5.2","depth":2,"path":"api/router-view.md","ref":"api/router-view.md","articles":[]},{"title":"路由信息对象","level":"1.5.3","depth":2,"path":"api/route-object.md","ref":"api/route-object.md","articles":[]},{"title":"Router 构造配置","level":"1.5.4","depth":2,"path":"api/options.md","ref":"api/options.md","articles":[]},{"title":"Router 实例","level":"1.5.5","depth":2,"path":"api/router-instance.md","ref":"api/router-instance.md","articles":[]},{"title":"对组件注入","level":"1.5.6","depth":2,"path":"api/component-injections.md","ref":"api/component-injections.md","articles":[]}]},"previous":{"title":"滚动行为","level":"1.4.5","depth":2,"path":"advanced/scroll-behavior.md","ref":"advanced/scroll-behavior.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"advanced/lazy-loading.md","mtime":"2017-03-04T12:16:27.888Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-03-06T16:00:44.406Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

